#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <iomanip>

#include "Vehicle.h"
#include "VehicleRegister.h"
#include "VehicleDataBase.h"
#include "Car.h"
#include "FamilyCar.h"
#include "Lorry.h"
#include "MotorCycle.h"
#include "SportsCar.h"

using namespace std;

void main3_1()
{
	cout << "main3_1" << endl;
	Vehicle v1("Volvo", 1991, 9500, 11000);
	Vehicle v2;
	v2.setBrand("SAAB");
	v2.setYear(2001);
	v2.setPurchasingPrice(20000);
	v2.setPurchasingPrice(22000.50);
	cout << v1.getBrand() << ", " << v1.getYear() << ", " << v1.getPurchasingPrice() << ", " << v1.getSellingPrice() << endl;
	cout << v2.getBrand() << ", " << v2.getPurchasingPrice() << endl;
}

void main3_2()
{
	cout << "main3_2" << endl;
	Vehicle v;
	v.read();
	v.write();
}

void main3_3()
{
	cout << "main3_3" << endl;
	Vehicle v1("Volvo", 1991, 9500, 11000);
	cout << v1 << endl;
	Vehicle v2;
	istringstream iss("(SAAB,1980,2500,3000)");
	iss >> v2;
	cout << v2 << endl;
}

void main3_4()
{
	cout << "main3_4" << endl;
	Vehicle v1("Volvo", 1991, 9500, 11000);
	Vehicle v2("SAAB",2001,20000,22000.50);
	Vehicle v3("Opel", 1980, 2000, 2200.50);
	VehicleRegister vr;
	vr.Add(v1);
	vr.Add(v2);
	vr.Add(v3);
	cout << vr.List() << endl;
	vr.Delete(1);
	cout << vr.List();
}

void main3_5()
{
	cout << "main3_5" << endl;
	Vehicle v1("Volvo", 1991, 9500, 11000);
	Vehicle v2,v3;
	istringstream iss("(SAAB,1980,2500,3000)");
	iss >> v2;
	v3.read();
	VehicleRegister vr("KallesBil");
	vr.Add(v1);
	vr.Add(v2);
	vr.Add(v3);
	vr.WriteToFile("test.txt");
}

void main3_6()
{
	cout << "main3_6" << endl;
	VehicleRegister vr;
	vr.ReadFromFile("test.txt");
	cout << vr.List();
}

void main3_7()
{
	cout << "main3_7" << endl;
	VehicleRegister vr;
	vr.ReadFromFile("test.txt");
	cout << vr.CalculateStorageValue() << endl;
}

void main4_1()
{
	cout << "main4_1" << endl;
	Vehicle v1("Volvo", 1991, 9600, 12000);
	Vehicle v2("SAAB", 2002, 22000, 24000.50);
	Vehicle v3("Opel", 1981, 2500, 2700.50);
	VehicleRegister vr("Arnes Bil");
	vr.Add(v1);
	vr.Add(v2);
	vr.Add(v3);

	VehicleRegister vr2;
	vr2.ReadFromFile("test.txt");

	VehicleDataBase vdb;
	vdb.Add(vr);
	vdb.Add(vr2);
	cout << vdb.FindVehicles("Volvo", 1991);
}

void main4_2()
{
	cout << "main4_2" << endl;
	Vehicle v1("Volvo", 1991, 9600, 12000);
	Vehicle v2("SAAB", 2002, 22000, 24000.50);
	Vehicle v3("Opel", 1981, 2500, 2700.50);
	VehicleRegister vr("Arnes Bil");
	vr.Add(v1);
	vr.Add(v2);
	vr.Add(v3);

	VehicleRegister vr2;
	vr2.ReadFromFile("test.txt");

	VehicleDataBase vdb;
	vdb.Add(vr);
	vdb.Add(vr2);

	vdb.menu();
}

void main5_1()
{
	cout << "main5_1" << endl;
	Vehicle veh("Volvo", 1990, 20000, 22000);
	Lorry l("Scania", 1990, 100000, 120000, 35);
	Car c("SAAB", 1991, 22000, 22500, 5, 5);
	MotorCycle mc("Yamaha", 2000, 50000, 60000, 2);
	FamilyCar fc("Skoda", 2002, 45000, 50000, 7, 5);
	SportsCar sc("Ferrari", 1970, 350000, 40000, 2, 2, 190);
	vector<Vehicle*> v;
	v.push_back(&veh);
	v.push_back(&l);
	v.push_back(&c);
	v.push_back(&mc);
	v.push_back(&fc);
	v.push_back(&sc);

	for (int i = 0; i < v.size(); i++)
	{
		(*v[i]).print();
		cout << endl;
	}
}

void main5_2()
{
	try
	{
		Vehicle v1("Volvo", 1991, 9600, 12000);
		Vehicle v2("SAAB", 2200, 22000, 24000.50);
	}
	catch (VehicleException ve)
	{
		cout << "Exception thrown: " << ve.getMessage() << endl;
	}
}

int main()
{
	//main3_1();
	//main3_2();
	//main3_3();
	//main3_4();
	//main3_5();
	//main3_6();
	//main3_7();
	//main4_1();
	//main4_2();
	//main5_1();
	main5_2();
	system("pause");
	return 0;
}